<?php

// abstract definition for an SOS request, extends OGC
abstract class SOS extends OGC
{
    // Sets up SOS specific operations
    function __construct()
    {
        parent::__construct();
        
        $this->allowed_operations['DescribeSensor'] =
            array( 'template' => '/route/to/default/template',
                   'params' => array (
                           'service'  => array( 
                                                'route' => "//*[local-name()='DescribeSensor']/@service",
                                                'value' => 'SOS' ), 
                           'procedure' => array(
                                                 'route' => "//*[local-name()='DescribeSensor']/sos:procedure",
                                                 'value' => '' )));
        $this->allowed_operations['GetObservation'] =
            array( 'template' => '/route/to/default/template',
                   'params' => array (
                           'service'  => array(
                                                'route' => "//*[local-name()='GetObservation']/@service",
                                                'value' => 'SOS' ), 
                           'beginPosition'  => array( 
                                                'route' => "//*[local-name()='GetObservation']/sos:eventTime/ogc:TM_During/gml:TimePeriod/gml:beginPosition",
                                                'value' => '' ), 
                           'endPosition'  => array(
                                                'route' => "//*[local-name()='GetObservation']/sos:eventTime/ogc:TM_During/gml:TimePeriod/gml:endPosition",
                                                'value' => '' ), 
                           'endIndeterminate'  => array( 
                                                'route' => "//*[local-name()='GetObservation']/sos:eventTime/ogc:TM_During/gml:TimePeriod/gml:endPosition/@indeterminatePosition",
                                                'value' => '' ), 
                           'observedProperty'  => array(
                                                'route' => "//*[local-name()='GetObservation']/sos:observedProperty",
                                                'value' => '' )));
        $this->setService( 'SOS' );
    }

    public function __destruct()
    {
        parent::__destruct();
    }

    // Returns GetObservation, only checks some generic things, data is picked up
    // in the local sos that implements getObservationReply()
    public function getObservation()
    {
        if ( $this->operationref == null )
        {
            $this->exception[] = array('code' => 'MissingParameterValue', 'Message' => 'No operation has been specified.' );
            return false;
        }

        return $this->getObservationReply();
    }

    // Returns DescribeSensor, the procedure needs to be validated in the local SOS that implements
    // getDescribeSensorReply().
    public function describeSensor()
    {
        if ( $this->operationref == null )
        {
            $this->exception[] = array('code' => 'MissingParameterValue', 'Message' => 'No operation has been specified.' );
            return false;
        }

        return $this->describeSensorReply();
    }

    // abstract methods that always have local dependencies (database access, etc)

    // retrieves data from the database for GetObservation
    abstract public function getObservationReply();

    // returns the DescribeSensor information - 
    // abstract since local code needs to check for a valid procedure
    abstract public function describeSensorReply();

    // implemented methods

    // test function to show parameters
    public function print_parameters() { print_r( $this->parameters ); }
}


?>
